home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / code_gen / vbxwzrd / redgreen.c# < prev    next >
Encoding:
Text File  |  1995-03-19  |  5.9 KB  |  177 lines

  1. //---------------------------------------------------------------------------
  2. // RedGreen.c
  3. //---------------------------------------------------------------------------
  4. // Contains control procedure for RedGreen control
  5. //---------------------------------------------------------------------------
  6.  
  7. #include <windows.h>
  8. #include "vbapi.h"
  9. #include "RedGreen.h"
  10.  
  11. //---------------------------------------------------------------------------
  12. // Local Prototypes
  13. //---------------------------------------------------------------------------
  14. BOOL _export FAR PASCAL AboutDlgProc(HWND hDlg, USHORT msg, USHORT wp, LONG lp);
  15.  
  16. //---------------------------------------------------------------------------
  17. // Global Variables
  18. //---------------------------------------------------------------------------
  19. HANDLE hmodDLL;
  20. HBITMAP RG;
  21.  
  22. //---------------------------------------------------------------------------
  23. // RedGreen Control Procedure
  24. //---------------------------------------------------------------------------
  25. LONG FAR PASCAL _export RedGreenCtlProc
  26. (
  27.     HCTL   hctl,
  28.     HWND   hwnd,
  29.     USHORT msg,
  30.     USHORT wp,
  31.     LONG   lp
  32. )            
  33. {
  34.     switch (msg)
  35.         {
  36.         case WM_CREATE:
  37.             SetWindowPos(hwnd, 0, 0, 0, 29, 16, SWP_NOMOVE);
  38.             break;
  39.         case WM_PAINT:
  40.             {
  41.             PAINTSTRUCT ps;
  42.             BOOL Value;
  43.             HDC  MemDC; 
  44.             HBRUSH hBrush;
  45.                 HBRUSH hBrushOld;
  46.                 BeginPaint(hwnd, &ps);
  47.  
  48.                 hBrush = (HBRUSH)GetBrushOrg(ps.hdc);
  49.                 if (hBrush) hBrushOld = SelectObject(ps.hdc, hBrush);
  50.                 MemDC = CreateCompatibleDC(ps.hdc);
  51.                 SelectObject(MemDC, RG);
  52.                 VBGetControlProperty(hctl, IPROP_RedGreen_Value, &Value);
  53.                 if (Value) BitBlt(ps.hdc, 0, 0, 29, 16, MemDC, 0, 0, SRCCOPY);
  54.                 else BitBlt(ps.hdc, 0, 0, 29, 16, MemDC, 0, 16, SRCCOPY);
  55.                 SelectObject(ps.hdc, hBrushOld);
  56.                 DeleteDC(MemDC);
  57.  
  58.                 EndPaint(hwnd, &ps);
  59.                 break;
  60.                 }
  61.           case VBM_SETPROPERTY:
  62.                 if (wp==IPROP_RedGreen_Value) InvalidateRect(hwnd, NULL, FALSE);
  63.                 break;
  64.           case WM_USER:
  65.             VBDialogBoxParam(hmodDLL, "ABOUT", (FARPROC)AboutDlgProc, 0L);
  66.             break;
  67.         case VBM_INITPROPPOPUP:
  68.             if (wp==3)
  69.                 {
  70.                   PostMessage(hwnd,WM_USER,0,0);
  71.                   return (lp+1)&&(0xFFFF);
  72.                 }
  73.             break;
  74.         }
  75.     return VBDefControlProc(hctl, hwnd, msg, wp, lp);
  76. }
  77. // This routine handles the 'About' Dialog Box messages 
  78. BOOL FAR PASCAL _export AboutDlgProc
  79. (
  80.     HWND   hDlg,
  81.     USHORT msg,
  82.     USHORT wp,
  83.     LONG   lp
  84. )
  85. {
  86.     switch (msg)
  87.         {
  88.           case WM_CREATE:
  89.               // Avoid warnings on unused (but required) formal parameters
  90.                 lp = lp;
  91.             return TRUE;
  92.         case WM_INITDIALOG:
  93.             return FALSE;
  94.         case WM_COMMAND:
  95.             if ((wp==IDOK)||(wp==IDCANCEL))
  96.                     EndDialog(hDlg, TRUE);
  97.                     return TRUE;
  98.         }
  99.     return FALSE;
  100. }
  101. //---------------------------------------------------------------------------
  102. // Register custom control. This routine is called by VB when the custom
  103. // control DLL is loaded for use.
  104. //---------------------------------------------------------------------------
  105. BOOL FAR PASCAL _export VBINITCC
  106. (
  107.     USHORT usVersion,
  108.     BOOL   fRuntime
  109. )
  110. {
  111.     // Avoid warnings on unused (but required) formal parameters
  112.     fRuntime  = fRuntime;
  113.     usVersion = usVersion;
  114.     // Register control(s)
  115.     return VBRegisterModel(hmodDLL, &modelRedGreen);
  116. }
  117.  
  118.  
  119. //---------------------------------------------------------------------------
  120. // Initialize library.  This routine is called when the first client loads
  121. // the DLL.
  122. //---------------------------------------------------------------------------
  123. int FAR PASCAL LibMain
  124. (
  125.     HANDLE hModule,
  126.     WORD   wDataSeg,
  127.     WORD   cbHeapSize,
  128.     LPSTR  lpszCmdLine
  129. )
  130. {
  131.     // Avoid warnings on unused (but required) formal parameters
  132.     wDataSeg    = wDataSeg;
  133.     cbHeapSize  = cbHeapSize;
  134.     lpszCmdLine = lpszCmdLine;
  135.  
  136.     hmodDLL = hModule;
  137.     RG = LoadBitmap(hmodDLL, "REDGREEN");
  138.     return 1;
  139. }
  140. //---------------------------------------------------------------------------
  141. // WEP
  142. //---------------------------------------------------------------------------
  143. // C7 and QCWIN provide default a WEP:
  144. //---------------------------------------------------------------------------
  145. #if (_MSC_VER < 610)
  146. int FAR PASCAL WEP(int fSystemExit);
  147. //---------------------------------------------------------------------------
  148. // For Windows 3.0 it is recommended that the WEP function reside in a
  149. // FIXED code segment and be exported as RESIDENTNAME.  This is
  150. // accomplished using the alloc_text pragma below and the related EXPORTS
  151. // and SEGMENTS directives in the .DEF file.
  152. //
  153. // Read the comments section documenting the WEP function in the Windows
  154. // 3.1 SDK "Programmers Reference, Volume 2: Functions" before placing
  155. // any additional code in the WEP routine for a Windows 3.0 DLL.
  156. //---------------------------------------------------------------------------
  157. #pragma alloc_text(WEP_TEXT,WEP)
  158. //---------------------------------------------------------------------------
  159. // Performs cleanup tasks when the DLL is unloaded.  WEP() is
  160. // called automatically by Windows when the DLL is unloaded (no
  161. // remaining tasks still have the DLL loaded).    It is strongly
  162. // recommended that a DLL have a WEP() function, even if it does
  163. // nothing but returns success (1), as in this example.
  164. //---------------------------------------------------------------------------
  165. int FAR PASCAL WEP
  166. (
  167.     int fSystemExit
  168. )
  169.     DeleteObject(RG);
  170.     // Avoid warnings on unused (but required) formal parameters
  171.     fSystemExit = fSystemExit;
  172.     return 1;
  173. }
  174. #endif // C6
  175. //---------------------------------------------------------------------------
  176.